# 作业一：
# 在服务器上自己的crmeb
# 1、登录
# 2、添加用户分组——》删除刚才新增的用户分组
# 3、添加是否成功，断言；删除是否成功，断言
# 组件化，元素与脚本分离
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# class Crmeb:
#     def __init__(self,url,brwoser):
#         self.brwoser = brwoser
#         self.brwoser.get(url)
#         self.brwoser.maximize_window()
#         self.brwoser.implicitly_wait(15)
#         time.sleep(5)
#     def lohin(self,username,password):
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "el-input__inner")))[0].send_keys(username)
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "el-input__inner")))[1].send_keys(password)
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located((By.XPATH, "//*[text()='登录']"))).click()
#         time.sleep(5)
#     def app_group (self,groupName):
#         self.groupName=groupName
#         time.sleep(5)
#         WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"layout-columns")))[1].click()
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located((By.XPATH, "//*[text()='用户分组']"))).click()
#         time.sleep(3)
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_element_located((By.XPATH, "//*[text()='添加分组']"))).click()
#         time.sleep(3)
#         WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,"el-input__inner")))[2].send_keys(self.groupName)
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "el-button")))[2].click()
#         time.sleep(3)
#     def assert_add(self):
#         text = WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_element_located((By.XPATH,f"//*[text()='{self.groupName}']"))).text
#         assert text == self.groupName
#     def delete_group(self):
#         WebDriverWait(self.brwoser,10,0.5).until(EC.presence_of_all_elements_located((By.XPATH, "//*[text()='删除']")))[-1].click()
#         WebDriverWait(self.brwoser, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, "el-button")))[-1].click()
# if __name__ == '__main__':
#     driver = webdriver.Chrome()
#     url = "http://121.40.86.4:8899/admin/login"
    # c1 = Crmeb(url, driver)
    # c1.login("admin", "Aa010903!")
    # c1.add_group("啊实打实的")
    # c1.assert_add()
    # c1.delete_group()

#
# 作业二：
# QQ音乐登录：https://y.qq.com/portal/pop_login.html
# import time
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.ui import WebDriverWait
# from selenium.webdriver.support import expected_conditions as EC
# driver = webdriver.Chrome()
# driver.get("https://y.qq.com/portal/pop_login.html")
# driver.maximize_window(·)
# driver.implicitly_wait(15)
# iframe = driver.find_elements(By.TAG_NAME,"iframe")
# driver.switch_to.frame(iframe[0])
# driver.find_element(By.ID,"img_out_1016376434").click()
# time.sleep(3)
#
# 作业三-crmeb：
# 1、添加用户标签——》删除刚才新增的用户标签
# 2、添加是否成功，断言；删除是否成功，断言
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("http://121.40.86.4:8899/admin/login")
driver.maximize_window()
driver.implicitly_wait(15)
time.sleep(5)
driver.find_elements(By.CLASS_NAME,"el-input__inner")[0].send_keys("admin")
driver.find_elements(By.CLASS_NAME,"el-input__inner")[1].send_keys("Aa010903!")
driver.find_element(By.XPATH,"//*[text()='登录']").click()
time.sleep(5)
driver.find_elements(By.CLASS_NAME,"font12")[1].click()
time.sleep(5)
driver.find_element(By.XPATH,"//*[text()='用户标签']").click()
time.sleep(5)
# 添加内容
driver.find_elements(By.CLASS_NAME,"el-input__inner")[3].send_keys("你好wjy")
driver.find_elements(By.CLASS_NAME,"el-button")[2].click()
time.sleep(5)
# 断言是否成功加入
text = driver.find_element(By.XPATH,"//*[text()='wangjingyao']").text
assert text == '你好wjy'
time.sleep(2)
driver.find_element(By.XPATH, "//*[@id='app']/section/div[2]/section/div/div[1]/div/main/div/div[1]/div/div[1]/div/div/div[2]/div/div/div[2]/div[4]/div[2]/table/tbody/tr[1]/td[4]/div/a[2]").click()
driver.find_element(By.XPATH,"/html/body/div[2]/div/div[3]/button[2]/span").click